package com.voicecheck.adapter;

import java.util.List;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aris.voicechecking.R;
import com.voicecheck.adapter.WeekLessonAdapter.LessonHolder;
import com.voicecheck.model.WeekLesson;

public class WeekLessonAdapter extends RecyclerView.Adapter<LessonHolder> {

	protected List<WeekLesson> listData;

	static OnItemClickListener mItemClickListener;

	public WeekLessonAdapter(List<WeekLesson> ldata) {
		listData = ldata;
	}

	@Override
	public int getItemCount() {

		return listData.size();

	}

	@Override
	public void onBindViewHolder(LessonHolder arg0, int arg1) {
		WeekLesson less = listData.get(arg1);
		arg0.tittle.setText(less.getTitle());

	}

	@Override
	public LessonHolder onCreateViewHolder(ViewGroup arg0, int arg1) {

		View contentView = LayoutInflater.from(arg0.getContext()).inflate(
				R.layout.item_lesson_week, arg0, false);

		return new LessonHolder(contentView);

	}

	public static class LessonHolder extends RecyclerView.ViewHolder implements
			View.OnClickListener {

		TextView tittle;

		public LessonHolder(View itemView) {
			super(itemView);

			tittle = (TextView) itemView.findViewById(R.id.lesson_title);
			itemView.setOnClickListener(this);

		}

		@Override
		public void onClick(View v) {

			if (WeekLessonAdapter.mItemClickListener != null) {
				WeekLessonAdapter.mItemClickListener.onItemClick(v,
						getPosition());
			}

		}

	}

	public interface OnItemClickListener {
		public void onItemClick(View view, int position);
	}

	public void SetOnItemClickListener(
			final OnItemClickListener mItemClickListener) {
		WeekLessonAdapter.mItemClickListener = mItemClickListener;
	}

}
